package com.design.graduation.asdemo.base;

import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.design.graduation.asdemo.R;

import java.lang.reflect.Field;


/**
 * @author by weijianxing on 11/3/15.
 */
public abstract class ActionBarActivity extends BaseActivity {

    protected TextView mTitleView;
    protected ImageButton mLeftButton;
    protected ImageButton mRightButton;
    protected TextView mRightTextView;
    protected Button mServiceButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    private View inflateActionBarView(int layoutID) {
        final ActionBar.LayoutParams titleBarlp = new ActionBar.LayoutParams(ActionBar
                .LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT, Gravity.END);
        View titleBar = getLayoutInflater().inflate(layoutID, null);
//        mTitleView = (TextView) titleBar.findViewById(titleID);
//        mLeftButton = (ImageButton) titleBar.findViewById(leftMenuID);
//        mRightButton = (ImageButton) titleBar.findViewById(rightMenuID);
        final ActionBar actionBar = getActionBar();
        actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setCustomView(titleBar, titleBarlp);
        return titleBar;
    }

    public void initNormalActionBar() {
        View titleBar = inflateActionBarView(R.layout.title_bar);
        mTitleView = (TextView) titleBar.findViewById(R.id.title_bar_title);
        mLeftButton = (ImageButton) titleBar.findViewById(R.id.title_bar_left_menu);
        mRightButton = (ImageButton) titleBar.findViewById(R.id.title_bar_right_menu);
        mRightTextView = (TextView) titleBar.findViewById(R.id.right_title_menu);
    }


    public void setTitle(String title) {
        mTitleView.setText(title);
    }

    public void setTitle(int resourceId) {
        mTitleView.setText(resourceId);
    }

    private String getPageTitle() {
        return mTitleView.getText().toString().trim();
    }

    public void setLeftMenuIcon(int iconId) {
        mLeftButton.setVisibility(View.VISIBLE);
        mLeftButton.setImageResource(iconId);
    }

    public void setRightMenuIcon(int resourceId) {
        mRightButton.setVisibility(View.VISIBLE);
        mRightButton.setImageResource(resourceId);
    }

    public void setRightMenuText(String text) {
        mRightTextView.setVisibility(View.VISIBLE);
        mRightTextView.setText(text);
    }

    public void hideMenu() {
        mLeftButton.setVisibility(View.INVISIBLE);
        mRightButton.setVisibility(View.INVISIBLE);
    }



    public void onLeftMenuClicked(View view) {
        finish();
    }
    public void onRightMenuClicked(View view) {

    }

    public void cancelWorkOrder(long workOrderId) {

    }


}
